/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cw.ulti;

/**
 *
 * @author VinhTC
 */
public class Validator {

    public Validator() {
    }

    /**
     * checkNull
     * @param input
     * @return
     */
    public static boolean checkNull(String input) {
        if (input.trim() != null && input.trim().length() > 0) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * validateEmail
     * @param email
     * @return
     */
    public static boolean validateEmail(String email) {
        final String eMailRegex = "^[\\w-_\\.+]*[\\w-_\\.]\\@([\\w]+\\.)+[\\w]+[\\w]$";
        if (email.trim() != null || email.trim().length() > 0) {
            if (email.matches(eMailRegex)) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    /**
     * main for test
     * @param args
     */
    public static void main(String[] args) {
        System.out.println("isValid = " + validateEmail("user@domain.com"));
        System.out.println("isValid = " + validateEmail("user.name@domain.com"));
        System.out.println("isValid = " + validateEmail("user.name@domain.com.sg"));
        System.out.println("isValid = " + validateEmail("user.domain.com.sg"));
    }
}
